<!--
* @FileDescription: tabbar的切换
* @Author: chenz
* @Date: 2021/4/14
* @LastEditors: 最后更新作者
* @LastEditTime: 最后更新时间
-->
<template>
	<view class="uni-tabbar">
		<view class="uni-tabbar__item" v-for="(item,index) in tabbar" :key="index" @tap="changeTab(item)">
			<view class="uni-tabbar__bd">
				<view class="uni-tabbar__icon">
					<image v-if="item.pagePath == pagePath" class="icon-img" mode="aspectFit" :src="item.selectedIconPath"></image>
					<image v-else class="icon-img" mode="aspectFit" :src="item.iconPath"></image>
				</view>
			</view>
			<!-- 高亮 -->
			<view class="uni-tabbar__label" :class="{'active': item.pagePath == pagePath}">
				{{item.text}}
			</view>
		</view>
	</view>

</template>

<script>
	export default {
		props: {
			pagePath: String,
			type: String
		},
		data() {
			return {
				page: 'contact',
				showPage: false,
				containerHeight: 400,
				tabbar: []
			};
		},
		watch: {
			pagePath: {
				handler(val) {
					// console.log('pagePath监听===val', val)
				},
				immediate: true
			}
		},
		mounted(options) {
			// console.log(this.type)
			// 根据自己的业务需求判断条件为true，替换即可
			if (this.type == 1) {
				this.tabbar.splice(0, 0, {
					"pagePath": "/pagesA/index/index",
					"iconPath": "/static/img/receipt.png",
					"selectedIconPath": "/static/img/receipt_on.png",
					"text": "预约"
				}, {
					"pagePath": "/pagesA/shopCar/shopCar",
					"iconPath": "/static/img/n_send.png",
					"selectedIconPath": "/static/img/n_send_on.png",
					"text": "购物车"
				}, {
					"pagePath": "/pagesA/my/my",
					"iconPath": "/static/apply.png",
					"selectedIconPath": "/static/apply_on.png",
					"text": "我的"
				})
			} else if (this.type == 2) {
				this.tabbar.splice(0, 0, {
					"pagePath": "/pagesB/index/index",
					"iconPath": "/static/img/today.png",
					"selectedIconPath": "/static/img/todayActive.png",
					"text": "今日任务"
				}, {
					"pagePath": "/pagesB/taskhall/taskhall",
					"iconPath": "/static/img/mission.png",
					"selectedIconPath": "/static/img/missionActive.png",
					"text": "任务大厅"
				}, {
					"pagePath": "/pagesB/my/my",
					"iconPath": "/static/img/my.png",
					"selectedIconPath": "/static/img/myActive.png",
					"text": "我的"
				})
			}else if (this.type == 3) {
				this.tabbar.splice(0, 0, {
					"pagePath": "/pagesC/index/index",
					"iconPath": "/static/img/today.png",
					"selectedIconPath": "/static/img/todayActive.png",
					"text": "图表"
				}, {
					"pagePath": "/pagesC/my/my",
					"iconPath": "/static/img/my.png",
					"selectedIconPath": "/static/img/myActive.png",
					"text": "管理"
				})
			}
		},
		methods: {
			changeTab(item) {
				this.page = item.pagePath;
				// 使用reLaunch关闭所有的页面，打开新的栏目页面
				uni.reLaunch({
					url: this.page
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.uni-tabbar {
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 999;
		width: 100%;
		display: flex;
		justify-content: space-around;
		height: 98upx;
		padding: 16upx 0;
		box-sizing: border-box;
		border-top: solid 1upx #ccc;
		background-color: #fff;
		box-shadow: 0px 0px 17upx 1upx rgba(206, 206, 206, 0.32);

		.uni-tabbar__item {
			display: block;
			line-height: 24upx;
			font-size: 20upx;
			text-align: center;
			width: 25%;
		}

		.uni-tabbar__icon {
			height: 24px;
			line-height: 24px;
			text-align: center;
		}

		.icon {
			display: inline-block;
		}

		.uni-tabbar__label {
			line-height: 24upx;
			font-size: 24upx;
			color: #999;

			&.active {
				color: #1ca6ec;
			}
		}

		.icon-img {
			height: 24px;
			width: 24px;
		}
	}
</style>
